package fr.castorhoz.isi_connectivity_widget.database;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class DBAdapter 
{
	DataBaseHelper	DBHelper;
	Context			context;
	SQLiteDatabase	db;
	
	public DBAdapter(Context context)
	{
		this.context = context;
		DBHelper = new DataBaseHelper(context);
	}	
		
	public DBAdapter open()
	{
		db = DBHelper.getWritableDatabase();
		return this;
	}
	
	public void close(){
		db.close();
	}
	
	public void truncate()
	{
		db.execSQL("DELETE FROM appWidgetContent");
	}
		
	public long insertWidget(String widgetName) {
		ContentValues values = new ContentValues();
		values.put("widgetName", widgetName);
		return db.insert("appWidgetContent", null, values);
	}
	
	
	public boolean supressWidget(long id) {
		return db.delete("appWidgetContent", "_id="+id, null)>0;
	}
	
	public Cursor getWidgets() {
		return db.query("appWidgetContent", new String[]{
				"_id",
				"widgetName"}, null, null, null, null, null);
	}
}

